const webpackMerge = require('webpack-merge')
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin')

const baseConfig = require('./webpack.base.conf');

module.exports = webpackMerge(baseConfig, {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ExtractTextWebpackPlugin.extract([ 'css-loader' ])
      },
      {
        test: /\.scss$/,
        use: ExtractTextWebpackPlugin.extract([
          { loader: 'css-loader', options: { importLoaders: 2 } },
          'postcss-loader',
          'sass-loader'
        ])
      }
    ]
  },
  plugins: [
    new ExtractTextWebpackPlugin({
      filename: "styles/[name].css",
    })
  ],
  optimization: {
    splitChunks: {
      chunks: 'initial',
      cacheGroups: {
        commons: {
          test: /[\\/]node_modules[\\/]/,
          name: 'vendor',
          chunks: 'initial'
        }
      }
    }
  }
})
